package com.whenjun.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Configuration
public class TackledCharacterEncodingFilter extends CharacterEncodingFilter {

	@Override
	protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
		HttpServletRequest requestWrapper = null;
		if (request instanceof HttpServletRequest)
			requestWrapper = new TackledServletRequestWrapper(request);
		if (null == requestWrapper)
			super.doFilterInternal(request, response, filterChain);
		else
			super.doFilterInternal(requestWrapper, response, filterChain);
	}
}
